// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   SourceFile

package com.sgame.android.lang;

import android.os.Parcel;
import android.os.Parcelable;
import com.sgame.android.data.TunnelTransmittable;
import com.sgame.android.lang.MapJsonObject;
import org.json.JSONException;
import org.json.JSONObject;

// Referenced classes of package com.mobage.global.android.lang:
//            ErrorMap, SurrogateSerializableThrowable

public class Error extends Exception
    implements Parcelable, TunnelTransmittable
{

    public Error()
    {
    }

    public Error(int code, String description)
    {
        this.code = code;
        this.description = description;
        localizedDescription = description;
    }

    protected Error(int code, String description, Throwable cause)
    {
        this.code = code;
        this.description = description;
        localizedDescription = description;
        setCause(cause);
    }

    public Error(ErrorMap errorEnum)
    {
        code = errorEnum.getCode();
        description = errorEnum.getDescription();
        localizedDescription = errorEnum.getLocalizedDescription();
    }

    public Error(ErrorMap errorEnum, Throwable cause)
    {
        code = errorEnum.getCode();
        description = errorEnum.getDescription();
        localizedDescription = errorEnum.getLocalizedDescription();
        setCause(cause);
    }

    public int getCode()
    {
        return code;
    }

    public String getMessage()
    {
        return getDescription();
    }

    public String getDescription()
    {
        return description;
    }

    public String getLocalizedDescription()
    {
        if(localizedDescription != null)
            return localizedDescription;
        else
            return description;
    }

    public String getDomain()
    {
        return "AndroidNDK";
    }

    public Throwable getCause()
    {
        return cause;
    }

    public void setCause(Throwable cause)
    {
        if(SurrogateSerializableThrowable.isSerializable(cause))
        {
            this.cause = cause;
            return;
        } else
        {
            this.cause = new SurrogateSerializableThrowable(cause);
            return;
        }
    }

    public String toString()
    {
        return (new StringBuilder()).append(Integer.toString(getCode())).append(":").append(getDescription()).toString();
    }

    public int describeContents()
    {
        return 0;
    }

    public void writeToParcel(Parcel dest, int i)
    {
        dest.writeInt(code);
        dest.writeString(description);
        dest.writeString(localizedDescription);
        dest.writeArray(getStackTrace());
        Throwable cause = getCause();
        dest.writeSerializable(cause);
    }

    private Error(Parcel in)
    {
        code = in.readInt();
        description = in.readString();
        localizedDescription = in.readString();
        Object aobj[];
        StackTraceElement astacktraceelement[] = new StackTraceElement[(aobj = in.readArray(ClassLoader.getSystemClassLoader())).length];
        for(int i = 0; i < aobj.length; i++)
            astacktraceelement[i] = (StackTraceElement)aobj[i];

        setStackTrace(astacktraceelement);
        setCause((Throwable)in.readSerializable());
    }

    public String toJsonStringForTunnel()
    {
        JSONObject jsonobject = new JSONObject();
        try
        {
	        jsonobject.put("code", getCode());
	        jsonobject.put("description", getDescription());
	        jsonobject.put("localizedDescription", getLocalizedDescription());
		}
		catch (JSONException e) {
			throw new RuntimeException(e);
		}
        return MapJsonObject.toString("Error", jsonobject);
    }

    public void updateWithJsonObjectFromTunnel(JSONObject jsonObject)
    {
        code = jsonObject.optInt("code");
        description = jsonObject.optString("description");
        localizedDescription = jsonObject.optString("localizedDescription", description);
    }


    private static final long serialVersionUID = 0x7022e687730d39caL;
    private int code;
    private String description;
    private String localizedDescription;
    private Throwable cause;
    public static final android.os.Parcelable.Creator<Object> CREATOR = new android.os.Parcelable.Creator<Object>() {

        public final Object[] newArray(int i)
        {
            return new Error[i];
        }

        public final Object createFromParcel(Parcel parcel)
        {
            return new Error(parcel);
        }

    }
;

}
